package com.sky.rabc.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 许照
 * @className RedissonConfig
 * @description redis变量配置类
 * @date 2024/5/28
 */
public class RedissonConfig {
    /**
     * 构建RedissonClient ，classLoader获取redisson配置文件
     * @param fileName redisson配置文件
     * @return RedissonClient
     * @throws IOException IO异常，读取文件错误
     */
    public RedissonClient redissonClient(String fileName) throws IOException {
        ClassLoader classLoader = RedissonConfig.class.getClassLoader();
        try (InputStream resourceAsStream = classLoader.getResourceAsStream(fileName)) {
            Config config = Config.fromYAML(resourceAsStream);
            return Redisson.create(config);
        }
    }
}
